package com.yan_jiu_sheng.LeetCodeHot100.AC;

/**
 * https://leetcode.cn/problems/symmetric-tree/description/?envType=study-plan-v2&envId=top-100-liked
 * 通过
 *
 * @author yulongTian
 * @create 2024-06-01 14:38
 */
public class Test39 {
    public static void main(String[] args) {

    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    private boolean res = true;

    public boolean isSymmetric(TreeNode root) {
        duicheng(root, root);
        return res;
    }

    private void duicheng(TreeNode root1, TreeNode root2) {
        if (root1 == null && root2 == null) {
            return;
        } else if (root1 == null || root2 == null) {
            res = false;
            return;
        }

        //左
        duicheng(root1.left, root2.right);
        //右
        if (root1.val != root2.val) {
            res = false;
        }
        //根
        duicheng(root1.right, root2.left);
    }

}
